/*******************************************************************************
* 
* Jsoncpp Test
* 
* 
******************************************************************************/
#include "stdafx.h"
#include "CppUnitTest.h"

#include "json/json.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace std;

namespace ut
{
    TEST_CLASS(JsonTest)
    {
    public:

        TEST_METHOD(JsonTestMethod1)
        {
            Json::Value root;   // will contains the root value after parsing.
            Json::Reader reader;
            bool parsingSuccessful = reader.parse( "{\"jsoncpp\": \"miles\", \"bin\":[1179,2254]}", root );
            if ( !parsingSuccessful )
            {
                // report to the user the failure and their locations in the document.
                std::cout  << "Failed to parse configuration\n"
                    << reader.getFormatedErrorMessages();

                Logger::WriteMessage(reader.getFormatedErrorMessages().c_str());
                return;
            }

            string jsoncpp = root["jsoncpp"].asString();
            Logger::WriteMessage(jsoncpp.c_str());

            const Json::Value bin = root["bin"];
            int index = 0;
            int start = bin[index].asInt();
            index = 1;
            int length = bin[index].asInt();
            char msg[100];
            sprintf_s(msg, "%d, %d", start, length);
            Logger::WriteMessage(msg);

            //// Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
            //// such member.
            //std::string encoding = root.get("encoding", "UTF-8" ).asString();
            //// Get the value of the member of root named 'encoding', return a 'null' value if
            //// there is no such member.
            //const Json::Value plugins = root["plug-ins"];
            //for ( int index = 0; index < plugins.size(); ++index )  // Iterates over the sequence elements.
            //    loadPlugIn( plugins[index].asString() );

            //setIndentLength( root["indent"].get("length", 3).asInt() );
            //setIndentUseSpace( root["indent"].get("use_space", true).asBool() );

            //// ...
            //// At application shutdown to make the new configuration document:
            //// Since Json::Value has implicit constructor for all value types, it is not
            //// necessary to explicitly construct the Json::Value object:
            //root["encoding"] = getCurrentEncoding();
            //root["indent"]["length"] = getCurrentIndentLength();
            //root["indent"]["use_space"] = getCurrentIndentUseSpace();

        }

    };
}